package mochito.tools.syshook;

 
public class KeyboardHook
{
	public KeyboardHook()
	{
		( new PollThread(this) ).start();
	}
 
	protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();
 
	public void addEventListener(KeyboardEventListener listener)
	{
		listenerList.add( KeyboardEventListener.class, listener );
	}
 
	public void removeEventListener(KeyboardEventListener listener)
	{
		listenerList.remove( KeyboardEventListener.class, listener );
	}
 
	void keyPressed(KeyboardEvent event)
	{
		Object[] listeners = listenerList.getListenerList();
		for ( int i = 0; i < listeners.length; i += 2 )
		{
			if ( listeners[ i ] == KeyboardEventListener.class )
			{
				( (KeyboardEventListener)listeners[i + 1] ).GlobalKeyPressed( event );
			}
		}
	}
 
	void keyReleased(KeyboardEvent event)
	{
		Object[] listeners = listenerList.getListenerList();
		for ( int i = 0; i < listeners.length; i += 2 )
		{
			if ( listeners[ i ] == KeyboardEventListener.class )
			{
				( (KeyboardEventListener)listeners[i + 1] ).GlobalKeyReleased( event );
			}
		}
	}
}